<?php

namespace IDock\Insurance\ZFIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\ZFIC\Response\AllZFICResponse;
use IDock\Insurance\ZFIC\ZFICEnums;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends CommonResponse
{

    public $totalCount = 0;

    public function printerInit() :Response
    {
        $vehicleModelPrinter = new VehicleModelPrinter();
        if($this->get('state','') != '200'){
            throw new \Exception($this->getMessage());
        }
        $this->totalCount = $this->getData()['totalCount'] ?? 0;

        if(!empty($this->getData()['carList'])) foreach ($this->getData()['carList'] as $datum) {

            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $datum['vehicleCode'] ?? '';
            $vehiclePrinter->brandName = $datum['vehicleBrand'] ?? '';
            $vehiclePrinter->vehicleExhaust = $datum['exhaustScale'] ?? '';

            $vehiclePrinter->vehicleImport = 'I0';
            $vehiclePrinter->vehicleName = $datum['vehicleName'] ?? '';
            $vehiclePrinter->vehiclePrice = $datum['purchasePriceWithoutTax'] ?? '';
            $vehiclePrinter->vehiclePriceTax = $datum['purchasePrice'] ?? '';
            $vehiclePrinter->vehicleSeat = $datum['seat'] ?? '';
            $vehiclePrinter->familyName = $datum['familyName'] ?? '';
            $vehiclePrinter->power = '';
            $vehiclePrinter->vehicleYear = '';
            $vehiclePrinter->vehicleTonnage = $datum['toncount'] ?? '';
            $vehiclePrinter->wholeWeight = $datum['completeKerbMassMin'] ?? '';
            $typeCode = array_search($datum['fueltype'],ZFICEnums::$energyType);
            $vehiclePrinter->energyTypeCode =  $typeCode ?: 'E00';
            $vehiclePrinter->energyTypeName = $datum['fueltype'];
            $vehiclePrinter->item['fueltype'] = $datum['fueltype'];//存下燃油类型是汽油还是柴油
            $vehiclePrinter->item['brandName'] = $datum['vehicleBrand'];
            if($datum['fueltype'] == '电动' or $datum['fueltype'] == '插电式混合动力' or $datum['fueltype'] == '燃料电池'){
                $vehiclePrinter->isNewEnergy = '1';
            }

            $vehicleModelPrinter->setModelList($vehiclePrinter);
        }
        $this->printer = $vehicleModelPrinter;

        return $this;
    }
}
